package sis.testio.objectstream;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-07-29 13:52
* @notify 
* @version 1.0
*/

import junit.framework.TestCase;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestObjectStream extends TestCase {

    public void testObjectStream()throws Exception{
        Person p = new Person();
        p.setAge(11);
        p.setName("张三");
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("person.txt"));
        objectOutputStream.writeObject(p);
        objectOutputStream.close();

        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("person.txt"));
        Person p2 = (Person)objectInputStream.readObject();
        assertEquals(p.getAge(),p2.getAge());
        assertEquals(p.getName(),p2.getName());
        objectInputStream.close();
    }
}
